< previous page page_364 next page >

Page 364
0364-01.jpg
Figure 16.3
Although property procedures look like regular functions,
application code sees them as a property of the object.
When users access the Department property, the appropriate property procedure is executed. Usually, a good action to take is to somehow store the value, as in the following example, which uses a private variable:
Public FirstName As String
Public LastName As String
Public DateHired As Date
Public Salary As Currency
Private nDeptNum As Integer

Public Property Get Department() As String
    Select Case nDeptNum
        Case 1
            Department = "Marketing"
        Case 2
            Department = "Accounting"
        Case Else
            Department = ""
    End Select
End Property

Public Property Let Department(ByVal sNewValue As String)
    Select Case Trim$(UCase$(sNewValue))
        Case "MARKETING"
            nDeptNum = 1
        Case "ACCOUNTING"
            nDeptNum = 2
        Case Else
            nDeptNum = 0
    End Select
End Property
In the preceding code, the property procedure actually stores the value representing the employee's department in a private integer variable. However, users of the object always assign and return a string. In a real program, the property procedures might do all sorts of things to the value, including storing it in a database.
note.gif To make a property Read-Only, omit the Property Set or Property Let procedure. square.gif

 
< previous page page_364 next page >